package com.gadgets.cm01.auth.service.impl;

import com.gadgets.cm01.auth.dto.AuthorityQueryDTO;
import com.gadgets.cm01.auth.dto.AuthorityTreeDTO;
import com.gadgets.cm01.auth.pojo.Authority;
import com.gadgets.cm01.auth.repository.IAuthorityMapper;
import com.gadgets.cm01.auth.service.IAuthorityService;
import com.gadgets.framework.common.dto.Pagination;
import com.gadgets.framework.common.util.PaginationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author UncleXiu
 * @version V1.0.0
 * @data 2020-09-29
 *
 */
@Service
public class AuthorityServiceImpl implements IAuthorityService {

    @Autowired
    private IAuthorityMapper authorityMapper;

    /**
     * 条件查询菜单树信息
     *
     * @param queryDTO 查询条件
     *
     * @return 查询结果
     */
    @Override
    public AuthorityTreeDTO queryAndBuildAuthorityTree(AuthorityQueryDTO queryDTO) {
        List<Authority> authorities = queryAuthorityInfoByPagination(queryDTO,null);
        if(null==authorities || authorities.size()==0){
            return null;
        }
        return new AuthorityTreeDTO(authorities);
    }

    /**
     * 分页条件查询菜单列表
     *
     * @param queryDTO   查询条件
     * @param pagination 分页条件
     *
     * @return 查询结果
     */
    @Override
    public List<Authority> queryAuthorityInfoByPagination(AuthorityQueryDTO queryDTO, Pagination pagination) {
        PaginationUtil.bulidPaginationInfo(pagination);
        List<Authority> authorities = authorityMapper.selectAuthorityInfo(queryDTO);
        PaginationUtil.getPaginationResultInfo(authorities,pagination);
        return authorities;
    }
}
